package org.example.util;

import lombok.extern.slf4j.Slf4j;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;
import java.util.Arrays;
import java.util.List;

@Slf4j
public class Tess4JTest {
    public static void main(String[] args) {
        File dir = new File("C:\\Users\\30147\\IdeaProjects\\my_mes_backend");
        List<File> list = Arrays.stream(dir.listFiles()).filter(f -> f.getName().endsWith(".png")).toList();
        // 创建临时目录
        // 复制tessdata文件到临时目录
        ITesseract instance = new Tesseract();
        instance.setDatapath("C:\\software\\tessdata");
        instance.setLanguage("chi_sim"); // 设置识别语言为简体中文
        list.forEach(f -> {
            try {
                String result = instance.doOCR(f);
                System.out.println(result);
            } catch (TesseractException e) {
                log.error(e.getMessage());
            }
        });

    }
}

